﻿namespace Yom.WebService.Admin
{
    using System.Text;
    using System.Web;
    using Yom.Common;

    public class AdminLogin : AdminBase
    {
        public void OutWrite()
        {
            string Action = Factory.Request("Action");

            switch (Action)
            {
                case "Logout":
                    SiteLoad.Admin = new Yom.Model.Admin();
                    HttpContext.Current.Response.Cookies.Add(new HttpCookie(SiteLoad.Cookie + "_Admin", ""));
                    break;
                case "Check":
                    string username = Factory.Request("username");
                    string password = Factory.Request("password");
                    string code = Factory.Request("code");
                    string vali = SiteLoad.Code;
                    if (vali != code)
                    {
                        base.Response.Write("1");
                        base.Response.End();
                    }
                    Yom.Model.Admin model = new Yom.Data.Admin().GetModel(username, password.ToMd5());
                    if (model != null && model.AdminID > 0)
                    {
                        SiteLoad.Admin = model;
                        Response.Write("0");
                        Response.End();
                    }
                    else
                    {
                        Response.Write("2");
                        Response.End();
                    }
                    break;
                default:
                    StringBuilder builder = new StringBuilder();
                    builder.Append("<center><div id=\"nifty\">");
                    builder.Append("<b class=\"rtop\"><b class=\"r1\"></b><b class=\"r2\"></b><b class=\"r3\"></b><b class=\"r4\"></b></b>");
                    builder.Append("<div class=\"CTitle\">YomComic 控制面板 -- 管理登录</div>");
                    builder.Append("<div class=\"CLogo\"><img src=\"Images/Admin/login.gif\" alt=\"\" /></div>");
                    builder.Append("<div class=\"CContent\">");
                    builder.Append("<table width=\"100%\" border=\"0\" cellspacing=\"3\" cellpadding=\"0\">");
                    builder.Append("<tr><td align=\"right\" style=\"width:120px;\"><b>用户名：</b></td>");
                    builder.Append("<td align=\"left\"><input type=\"text\" id=\"username\" size=\"15\" /></td></tr>");
                    builder.Append("<tr><td align=\"right\"><b>密　码：</b></td>");
                    builder.Append("<td align=\"left\"><input type=\"password\" id=\"password\" size=\"17\" /></td></tr>");
                    builder.Append("<tr><td align=\"right\"><b>附加码：</b></td>");
                    builder.Append("<td align=\"left\"><input type=\"text\" id=\"code\" size=\"5\" maxlength=\"5\" />&nbsp;");
                    builder.Append("<img id=\"ValiCode\" src=\"Service.ashx?Action=ValiCode\" alt=\"验证码,看不清楚?请点击刷新验证码\" style=\"margin-right:17px;cursor:pointer;width:60px;height:20px;margin-bottom:-4px;margin-top:2px;\" /></td></tr>");
                    builder.Append("<tr><td align=\"right\"></td>");
                    builder.Append("<td align=\"left\"><input type=\"button\" id=\"btnLogin\" class=\"AdminSub\" style=\"padding-top:2px;\" value=\" 登陆 \" /></td></tr></table>");
                    builder.Append("<span id=\"ErrShow\" style=\"color:red\"></span></div>");
                    builder.Append("<div class=\"CopyRight\">CopyRight (c)2009 <a href=\"http://www.yomhut.com\" target=\"_blank\">YomHut</a>. All Rights. Reserved.</div>");
                    builder.Append("<b class=\"rbottom\"><b class=\"r4\"></b><b class=\"r3\"></b><b class=\"r2\"></b><b class=\"r1\"></b></b></div></center>");
                    base.Response.Write(builder.ToString());
                    break;
            }
        }
    }
}